import request from './request'
import type { Role, PaginationParams, PaginationResponse } from '@/types'

export const roleAPI = {
  getRoles: (params: PaginationParams & { name?: string }): Promise<PaginationResponse<Role>> => {
    return request.get('/roles', { params })
  },
  
  getRole: (id: number): Promise<Role> => {
    return request.get(`/roles/${id}`)
  },
  
  createRole: (data: {
    name: string
    description?: string
  }): Promise<Role> => {
    return request.post('/roles', data)
  },
  
  updateRole: (id: number, data: {
    name: string
    description?: string
  }): Promise<Role> => {
    return request.put(`/roles/${id}`, data)
  },
  
  deleteRole: (id: number): Promise<void> => {
    return request.delete(`/roles/${id}`)
  },
  
  updateRolePermissions: (id: number, permissionIds: number[]): Promise<void> => {
    return request.put(`/roles/${id}/permissions`, { permission_ids: permissionIds })
  }
}